package com.tjsinfo.tjsoa.meetingroom.dao;

import java.util.List;
import java.util.Set;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.tjsinfo.tjsoa.meetingroom.vo.IMeetingRoomMain;
import com.tjsinfo.tjsoa.meetingroom.vo.MeetingRoomMain;

/**
 * A data access object (DAO) providing persistence and search support for
 * MeetingRoomMain entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.tjsinfo.tjsoa.meetingroom.main.MeetingRoomMain
 * @author MyEclipse Persistence Tools
 */

public class MeetingRoomMainDAO extends HibernateDaoSupport implements IMeetingRoomMainDAO{
	private static final Log log = LogFactory.getLog(MeetingRoomMainDAO.class);
	// property constants
	public static final String MEETINGROOM_NAME = "meetingroomName";
	public static final String MEETINGROOM_ID = "meetingroomId";
	public static final String PEOPLE_NUMBERT = "peopleNumbert";					
	public static final String PLACE = "place";
	public static final String REMARKS = "remarks";

	protected void initDao() {
		// do nothing
	}

	public void save(IMeetingRoomMain transientInstance) {
		log.debug("saving MeetingRoomMain instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MeetingRoomMain persistentInstance) {
		log.debug("deleting MeetingRoomMain instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public IMeetingRoomMain findById(String id) {
		log.debug("getting MeetingRoomMain instance with id: " + id);
		try {
			IMeetingRoomMain instance = (IMeetingRoomMain) getHibernateTemplate()
					.get("com.tjsinfo.tjsoa.meetingroom.vo.MeetingRoomMain",
							id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}



	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MeetingRoomMain instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from MeetingRoomMain as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByMeetingroomName(Object meetingroomName) {
		return findByProperty(MEETINGROOM_NAME, meetingroomName);
	}

	public List findByMeetingroomId(Object meetingroomId) {
		return findByProperty(MEETINGROOM_ID, meetingroomId);
	}

	public List findByPeopleNumbert(Object peopleNumbert) {
		return findByProperty(PEOPLE_NUMBERT, peopleNumbert);
	}

	public List findByPlace(Object place) {
		return findByProperty(PLACE, place);
	}

	public List findByRemarks(Object remarks) {
		return findByProperty(REMARKS, remarks);
	}

	public List findAll() {
		log.debug("finding all MeetingRoomMain instances");
		try {
			Configuration configuration = new PropertiesConfiguration("com/tjsinfo/tjsoa/mail/properties/systemResource.properties");
		} catch (ConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			String queryString = "from MeetingRoomMain";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public IMeetingRoomMain merge(IMeetingRoomMain detachedInstance) {
		log.debug("merging MeetingRoomMain instance");
		try {
			IMeetingRoomMain result = (IMeetingRoomMain) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(IMeetingRoomMain instance) {
		log.debug("attaching dirty MeetingRoomMain instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(IMeetingRoomMain instance) {
		log.debug("attaching clean MeetingRoomMain instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static MeetingRoomMainDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (MeetingRoomMainDAO) ctx.getBean("MeetingRoomMainDAO");
	}
	public  void update(IMeetingRoomMain meetingRoomMain)
	{
		try {
			getHibernateTemplate().saveOrUpdate(meetingRoomMain);
		} catch (DataAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public  void delete(IMeetingRoomMain persistentInstance)
	{
		try {
			getHibernateTemplate().delete(persistentInstance);
		} catch (DataAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void update(Object object) {
		// TODO Auto-generated method stub
		try {
			getHibernateTemplate().saveOrUpdate(object);
		} catch (DataAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}